/**
 * Copyright 2015 - 2016 KeepSafe Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.getkeepsafe.relinker.elf;

import java.io.IOException;

/**
 * Function description
 * interface EIf
 */
public interface Elf {
    /**
     * Function description
     * class Dynamic64Structure
     */
    abstract class Header {
        /**
         * ELFCLASS32
         */
        public static final int ELFCLASS32 = 1; // 32 Bit ELF

        /**
         * ELFCLASS64
         */
        public static final int ELFCLASS64 = 2; // 64 Bit ELF

        /**
         * ELFDATA2MSB
         */
        public static final int ELFDATA2MSB = 2; // Big Endian, 2s complement

        /**
         * mIsBigEndian
         */
        protected boolean mIsBigEndian;

        /**
         * type
         */
        protected int type;

        /**
         * mPhoff
         */
        protected long mPhoff;

        /**
         * mShoff
         */
        protected long mShoff;

        /**
         * mPhentsize
         */
        protected int mPhentsize;

        /**
         * mPhnum
         */
        protected int mPhnum;

        /**
         * mShentsize
         */
        protected int mShentsize;

        /**
         * mShnum
         */
        protected int mShnum;

        /**
         * mShstrndx
         */
        protected int mShstrndx;

        /**
         * getSectionHeader
         *
         * @param index index
         * @return Elf.SectionHeader
         * @throws IOException
         */
        public abstract SectionHeader getSectionHeader(int index) throws IOException;

        /**
         * getProgramHeader
         *
         * @param index index
         * @return Elf.ProgramHeader
         * @throws IOException
         */
        public abstract ProgramHeader getProgramHeader(long index) throws IOException;

        /**
         * getDynamicStructure
         *
         * @param baseOffset baseOffset
         * @param index index
         * @return Elf.DynamicStructure
         * @throws IOException
         */
        public abstract DynamicStructure getDynamicStructure(long baseOffset, int index) throws IOException;
    }

    /**
     * Function description
     * class ProgramHeader
     *
     */
    abstract class ProgramHeader {
        /**
         * PT_LOAD
         */
        public static final int PT_LOAD = 1; // Loadable segment

        /**
         * PT_DYNAMIC
         */
        public static final int PT_DYNAMIC = 2; // Dynamic linking information

        /**
         * type
         */
        protected long type;

        /**
         * offset
         */
        protected long offset;

        /**
         * vaddr
         */
        protected long vaddr;

        /**
         * memsz
         */
        protected long memsz;
    }

    /**
     * Function description
     * class SectionHeader
     *
     */
    abstract class SectionHeader {
        /**
         * info
         */
        protected long info;
    }

    /**
     * Function description
     * class ProgramHeader
     */
    abstract class DynamicStructure {
        /**
         * DT_NULL
         */
        public static final int DT_NULL = 0; // Marks end of structure list

        /**
         * DT_NEEDED
         */
        public static final int DT_NEEDED = 1; // Needed library

        /**
         * DT_STRTAB
         */
        public static final int DT_STRTAB = 5; // String table

        /**
         * tag
         */
        protected long tag;

        /**
         * val
         */
        protected long val; // Union with d_ptr
    }
}
